namespace KPIS.GERP.Models.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class update0056 : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.SysApprovalTaskDtl", "AppPathDtlId", "dbo.SysApprovePathDtl");
            DropForeignKey("dbo.SysApprovePathDtl", "ExecPosGroupId", "dbo.sys_exec_pos_group");
            DropForeignKey("dbo.SysApprovePathDtl", "PosId", "dbo.hrm_mp_positions");
            DropForeignKey("dbo.SysApprovePathDtl", "AppPrcId", "dbo.SysApproveProcess");
            DropForeignKey("dbo.SysApprovePathDtl", "AppPathId", "dbo.SysApprovePath");
            DropIndex("dbo.SysApprovalTaskDtl", new[] { "AppPathDtlId" });
            DropIndex("dbo.SysApprovePathDtl", new[] { "ExecPosGroupId" });
            DropIndex("dbo.SysApprovePathDtl", new[] { "PosId" });
            DropIndex("dbo.SysApprovePathDtl", new[] { "AppPrcId" });
            DropIndex("dbo.SysApprovePathDtl", new[] { "AppPathId" });
            AddColumn("dbo.SysApprovalTaskDtl", "AppPathId", c => c.Int());
            AddColumn("dbo.SysApprovePath", "ApproverType", c => c.Int(nullable: false));
            AddColumn("dbo.SysApprovePath", "IsExecPosEmployeesOnlyInSameJobSitePath", c => c.Boolean(nullable: false));
            AddColumn("dbo.SysApprovePath", "IsApproveAble", c => c.Boolean(nullable: false));
            AddColumn("dbo.SysApprovePath", "IsForwardable", c => c.Boolean(nullable: false));
            AddColumn("dbo.SysApprovePath", "IsRejectable", c => c.Boolean(nullable: false));
            AddColumn("dbo.SysApprovePath", "IsPendable", c => c.Boolean(nullable: false));
            AddColumn("dbo.SysApprovePath", "IsSendBackable", c => c.Boolean(nullable: false));
            AddColumn("dbo.SysApprovePath", "IsLockable", c => c.Boolean(nullable: false));
            AddColumn("dbo.SysApprovePath", "IsTakebackAble", c => c.Boolean(nullable: false));
            AddColumn("dbo.SysApprovePath", "AmountMin", c => c.Decimal(precision: 18, scale: 2));
            AddColumn("dbo.SysApprovePath", "AmountMax", c => c.Decimal(precision: 18, scale: 2));
            AddColumn("dbo.SysApprovePath", "ExecPosGroupId", c => c.Int());
            AddColumn("dbo.SysApprovePath", "PosId", c => c.Int());
            AddForeignKey("dbo.SysApprovalTaskDtl", "AppPathId", "dbo.SysApprovePath", "AppPathId");
            AddForeignKey("dbo.SysApprovePath", "ExecPosGroupId", "dbo.sys_exec_pos_group", "exec_pos_group_seq");
            AddForeignKey("dbo.SysApprovePath", "PosId", "dbo.hrm_mp_positions", "pos_seq");
            CreateIndex("dbo.SysApprovalTaskDtl", "AppPathId");
            CreateIndex("dbo.SysApprovePath", "ExecPosGroupId");
            CreateIndex("dbo.SysApprovePath", "PosId");
            DropColumn("dbo.SysApprovalTaskDtl", "AppPathDtlId");
            DropTable("dbo.SysApprovePathDtl");
        }
        
        public override void Down()
        {
            CreateTable(
                "dbo.SysApprovePathDtl",
                c => new
                    {
                        AppPathDtlId = c.Int(nullable: false, identity: true),
                        ApproverType = c.Int(nullable: false),
                        IsExecPosEmployeesOnlyInSameJobSitePath = c.Boolean(nullable: false),
                        IsApproveAble = c.Boolean(nullable: false),
                        IsForwardable = c.Boolean(nullable: false),
                        IsRejectable = c.Boolean(nullable: false),
                        IsPendable = c.Boolean(nullable: false),
                        IsSendBackable = c.Boolean(nullable: false),
                        IsLockable = c.Boolean(nullable: false),
                        IsTakebackAble = c.Boolean(nullable: false),
                        AmountMin = c.Decimal(precision: 18, scale: 2),
                        AmountMax = c.Decimal(precision: 18, scale: 2),
                        AppPathId = c.Int(),
                        AppPrcId = c.Int(),
                        ExecPosGroupId = c.Int(),
                        PosId = c.Int(),
                        CreatedBy = c.Int(),
                        CreatedWhen = c.DateTime(nullable: false),
                        UpdatedBy = c.Int(),
                        UpdatedWhen = c.DateTime(),
                    })
                .PrimaryKey(t => t.AppPathDtlId);
            
            AddColumn("dbo.SysApprovalTaskDtl", "AppPathDtlId", c => c.Int());
            DropIndex("dbo.SysApprovePath", new[] { "PosId" });
            DropIndex("dbo.SysApprovePath", new[] { "ExecPosGroupId" });
            DropIndex("dbo.SysApprovalTaskDtl", new[] { "AppPathId" });
            DropForeignKey("dbo.SysApprovePath", "PosId", "dbo.hrm_mp_positions");
            DropForeignKey("dbo.SysApprovePath", "ExecPosGroupId", "dbo.sys_exec_pos_group");
            DropForeignKey("dbo.SysApprovalTaskDtl", "AppPathId", "dbo.SysApprovePath");
            DropColumn("dbo.SysApprovePath", "PosId");
            DropColumn("dbo.SysApprovePath", "ExecPosGroupId");
            DropColumn("dbo.SysApprovePath", "AmountMax");
            DropColumn("dbo.SysApprovePath", "AmountMin");
            DropColumn("dbo.SysApprovePath", "IsTakebackAble");
            DropColumn("dbo.SysApprovePath", "IsLockable");
            DropColumn("dbo.SysApprovePath", "IsSendBackable");
            DropColumn("dbo.SysApprovePath", "IsPendable");
            DropColumn("dbo.SysApprovePath", "IsRejectable");
            DropColumn("dbo.SysApprovePath", "IsForwardable");
            DropColumn("dbo.SysApprovePath", "IsApproveAble");
            DropColumn("dbo.SysApprovePath", "IsExecPosEmployeesOnlyInSameJobSitePath");
            DropColumn("dbo.SysApprovePath", "ApproverType");
            DropColumn("dbo.SysApprovalTaskDtl", "AppPathId");
            CreateIndex("dbo.SysApprovePathDtl", "AppPathId");
            CreateIndex("dbo.SysApprovePathDtl", "AppPrcId");
            CreateIndex("dbo.SysApprovePathDtl", "PosId");
            CreateIndex("dbo.SysApprovePathDtl", "ExecPosGroupId");
            CreateIndex("dbo.SysApprovalTaskDtl", "AppPathDtlId");
            AddForeignKey("dbo.SysApprovePathDtl", "AppPathId", "dbo.SysApprovePath", "AppPathId");
            AddForeignKey("dbo.SysApprovePathDtl", "AppPrcId", "dbo.SysApproveProcess", "AppPrcId");
            AddForeignKey("dbo.SysApprovePathDtl", "PosId", "dbo.hrm_mp_positions", "pos_seq");
            AddForeignKey("dbo.SysApprovePathDtl", "ExecPosGroupId", "dbo.sys_exec_pos_group", "exec_pos_group_seq");
            AddForeignKey("dbo.SysApprovalTaskDtl", "AppPathDtlId", "dbo.SysApprovePathDtl", "AppPathDtlId");
        }
    }
}
